<template>
  <!--流动检验-待办任务-->
  <el-container>
    <basic-crud ref="crudRef" :option="option" apiGetListUrl="/mes/specificationTaskController/listCheckTask"
                :fastSearch="{name:'计划编号、规程编号、规程名称',fastColumn:'sourceCode,code,name'}" selectType="multiple">
      <template #code="{ row }">
        <el-button type="text" @click="openRuleDetails(row)">{{row.code}}</el-button>
      </template>
      <template #firstArticleFlag="{ row }">
        <el-tag type="danger" v-if="row.firstArticleFlag === 'true'">首件</el-tag>
      </template>
      <template #menu-left>
        <el-button
            type="primary" plain
            icon="download"
            :loading="downloadLoading"
            v-permission="'treatCompleted-DOWNLOADCARD'"
            @click="openRuleDetails({id: 123})"
        >下载工卡</el-button>
      </template>
    </basic-crud>
  </el-container>
</template>

<script setup>
import { ref } from 'vue'
import { clearObjAttr } from '@/utils/index.js'
import { formatDate } from "@/utils/formatTime";
import {downloadCard} from "@/utils/file.js";
import { useRouterParamsStore } from '@/store/routerParams.js'
import { useRouter } from 'vue-router'
const router = useRouter()
// storeToRefs是保持数据的响应式
const { techne } = storeToRefs(useRouterParamsStore())

const option = {
  selection: true,
  addBtn: false,
  delBtn: false,
  editBtn: false,
  searchIndex: 3,
  searchIcon: true,
  menu:false,
  column: [
    {
      label: "状态",
      prop: "status",
      width: 80,
      slot: true,
      sortable:true,
      searchType: "select",
      virtualize:true,
      statusShow:true,
      statusTag:true,
      statusTypeMap: {
        Suspended:'danger',
        Obsoleted:'danger',
        ExecuteFinish:'success',
        Finish:'success'
      }
    },
    {
      label: "计划编号",
      prop: "sourceCode",
      width: 220,
      search:true,
      overHidden: true,
    },
    {
      label: "项目号",
      prop: "workOrderCode",
      width: 120,
      sortable:true,
      overHidden: true,
      search: true,
    },
    {
      label:'数量',
      prop:'quantity',
      width: 70,
      display:false
    },
    {
      label: "产品型号",
      prop: "modelName",
      width: 120,
      sortable:true,
      search: true,
    },
    {
      label: "产品名称",
      prop: "pdmProductName",
      overHidden: true,
      width: 120,
      sortable:true,
      search: true,
    },
    {
      label: "产品编号",
      prop: "pdmProductCode",
      width: 120,
      cell: true,
      sortable:true,
      search: true,
      overHidden: true,
    },
    {
      label: "首件标识",
      prop: "firstArticleFlag",
      width: 100,
      sortable:true,
      slot:true
    },
    {
      label: "规程编号",
      prop: "code",
      minWidth: 150,
      slot: "code",
      sortable:true,
      search: true,
    },
    {
      label: "规程名称",
      prop: "name",
      minWidth: 150,
      sortable:true,
      search: true,
    },
    {
      label: "规程版本",
      prop: "specificationRev",
      width: 70,
    },
    {
      label: "计划开始日期",
      prop: "needStartDate",
      sortable: true,
      width: 130,
      formatter: (row) => {
        return formatDate(row.needStartDate, "yyyy-MM-dd");
      },
    },
    {
      label: "计划完成日期",
      prop: "needEndDate",
      sortable: true,
      width: 130,
      formatter: (row) => {
        return formatDate(row.needEndDate, "yyyy-MM-dd");
      },
    },
    {
      label:'关重件',
      prop: 'importantSign',
      display: false,
      width: 100,
      sortable: true,
      type: 'select',
      search: true,
      searchType: 'select',
      dicData: [{
        label:'关键件',
        value: '1'
      },{
        label: '重要件',
        value: '2'
      },{
        label: '普通件',
        value: '3'
      }]
    },
    {
      label: "紧急程度",
      prop: "exigencyLevel",
      display: false,
      width: 90,
      type: "select",
      dicData: [
        {
          label: "不紧急",
          value: "none",
        },
        {
          label: "一般",
          value: "normal",
        },
        {
          label: "紧急",
          value: "exigency",
        },
        {
          label: "非常紧急",
          value: "veryExigency",
        },
      ],
      formatter: (val) => {
        return val.exigencyLevelText;
      },
    },
    {
      label: "军检",
      prop: "armyCheck",
      display: false,
      width:90,
      type: "switch",
      dicData: [{
        label: '否',
        value: 'false'
      },{
        label: '是',
        value:'true'
      }]
    },
    {
      label: "派工日期",
      prop: "allotDateTime",
      sortable: true,
      width: 130,
      formatter: (row) => {
        return formatDate(row.allotDateTime, "yyyy-MM-dd");
      },
    },
    {
      label: "开工日期",
      prop: "beginDate",
      sortable: true,
      width: 130,
      formatter: (row) => {
        return formatDate(row.beginDate, "yyyy-MM-dd");
      },
    },
    {
      label: "完工日期",
      prop: "finishDate",
      sortable: true,
      width: 130,
      formatter: (row) => {
        return formatDate(row.finishDate, "yyyy-MM-dd");
      },
    },
    {
      label: "主键",
      prop: "id",
      hide: true,
    },
  ],
}

const crudRef = ref(null)

// 打开规程弹窗
const openRuleDetails=( row) => {
  const params = { row: row, mode: "checker" };
  //techne.value = params
  router.push({
    path: "/techne",
    query:{
      type:"process",
      mode: "checker",
      specTaskId:row.id
    },
    params: {
      techneData: JSON.stringify({ row, mode: "checker" })
    }
  })
}
const downloadLoading = ref(false)
//下载工卡
const downloadProcessCard= async () => {
  if (crudRef.value.selectData.length <= 0) {
    return ElMessage.warning('至少选择一条数据！')
  }
  ElMessageBox.confirm("是否确认下载工卡吗?", "提示", {
    confirmButtonText: "确定",
    cancelButtonText: "取消",
    type: "warning",
  }).then(() => {
    downloadLoading.value=true;
    let taskIds = crudRef.value.selectData.map((item) => {
      return item.id;
    });
    downloadCard({ specificationTaskIds: taskIds.join(",") }, downloadLoading);
  });
}
</script>

<style scoped>

</style>